//
//  DSSHLoginViewController.m
//  DSSH
//
//  Created by Fuhao on 16/3/28.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHLoginViewController.h"
#import "DSSHRegistBaseV.h"
#import "RegistModel.h"
#define HIGHT_IPHONE 40
@interface DSSHLoginViewController ()<UITextFieldDelegate>
{
    CGFloat _keyhight;
    RegistModel *_dataM;
    
}





@end

@implementation DSSHLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    [self.view setBackgroundColor:[UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1]];
    
//    [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:202/255.0 green:24/255.0 blue:36/255.0 alpha:1]];
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [button setTitle:@"注册" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16.0];
    [button addTarget:self action:@selector(registerbutton) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStyleDone target:self action:@selector(registerbutton)];
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
    _login.layer.cornerRadius = 5.0;
    
    [self.navigationItem setTitle:@"登录"];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 
    
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSUserDefaults *usr = [NSUserDefaults standardUserDefaults];
    NSString *phone = [usr objectForKey:@"userphone"];
    if(phone){
        _phoneN.text = phone;
        _passW.text = [usr objectForKey:@"userPassWord"];
    }
}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark 登录／注册／找回
- (IBAction)login:(id)sender {
    AccountService *_server = [AccountService getObject];

    DSSHLog(@"登录");
    [_server login:_phoneN.text passw:_passW.text];
    _server.httpRequestResultBlock = ^(id result , int coder)
    {
        if(coder == NET_ERROR)
        {
            [self.view makeToast:@"网络连接异常"];
        }
    };
    _server.saveToGlobalData = ^(id data ,int coder)
    {
         _dataM= data;
        if([_dataM.retcode intValue] !=1)
        {
            [self.view makeToast:[NSString stringWithFormat:@"%@",_dataM.message]];
            return ;
        }
        DSSHLog(@"登录成功 !");
        
    };
    

   
}
-(IBAction)findpassword:(id)sender
{
    DSSHLog(@"找回");
    DSSHRegistBaseV *regist = [[DSSHRegistBaseV alloc] initwithstoryboard:@"RegistCom"];
    
    UIBarButtonItem *back = [[UIBarButtonItem alloc]init];
    back.title = @"";
    regist.typeofview = DSSHRegistBaseVTypeFind;
    self.navigationItem.backBarButtonItem  = back;
    [self.navigationController pushViewController:regist animated:YES];
    
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
- (void) keyboardWasShown:(NSNotification *) notif
{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    _keyhight = keyboardSize.height;
    
    
}
-(void)registerbutton
{
    DSSHLog(@"注册");
    DSSHRegistBaseV *regist = [[DSSHRegistBaseV alloc] initwithstoryboard:@"RegistCom"];
    UIBarButtonItem *back = [[UIBarButtonItem alloc]init];
    back.title = @"";
    regist.typeofview =  DSSHRegistBaseVTypeRegist;
       self.navigationItem.backBarButtonItem  = back;
    [self.navigationController pushViewController:regist animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
